﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using System.Data;
using KPIS.Utils;
using KPIS.DBM;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.MODEL;
using Telerik.Web.UI;


namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class TR_TrainingTypes : System.Web.UI.UserControl
    {
        private object _dataItem = null;
        InitialData_BLL iniData = new InitialData_BLL();
        ComboBLL combo = new ComboBLL();

        //ReadOnly property.
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }
        //Initializing the new variable updating ViewState data.
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (!IsUserControlPostBack)
            {
              
                this.ViewState.Add("IsUserControlPostBack", true); 
                bindCommandType();
            }

            //if (DataItem != null)
            //{
            //    if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
            //    {
            //        lblID.Text = DataBinder.Eval(DataItem, "training_type_seq").ToString();
            //        txtName.Text = DataBinder.Eval(DataItem, "training_type_descr").ToString();
                   
            //        this.btnAddnew.Visible = false;
            //        this.btnUpdate.Visible = true;
            //    }
            //    else
            //    {
            //        this.btnUpdate.Visible = false;
            //        this.btnAddnew.Visible = true;
            //    }
            //}           

            if (DataItem != null)
            {
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    lblID.Text = DataBinder.Eval(DataItem, "training_type_seq").ToString();
                    // ddlEmployeeType.SelectedValue = DataBinder.Eval(DataItem, "emp_type_seq").ToString();
                    //lblEmpType.Text = DataBinder.Eval(DataItem, "emp_type_seq").ToString();
                    //txtCode.Text = DataBinder.Eval(DataItem, "ext_code").ToString();
                    txtName.Text = DataBinder.Eval(DataItem, "training_type_descr").ToString();
                    //txtNameShort.Text = DataBinder.Eval(DataItem, "ext_name_short").ToString();
                    //txtExtAmount.Text = DataBinder.Eval(DataItem, "ext_amount", "{0:N2}").ToString();
                    string inter = DataBinder.Eval(DataItem, "internal").ToString();
                    if (inter == "1")
                        rdoInternal.Items[0].Selected = true;
                    else
                        rdoInternal.Items[1].Selected = true;
                    string local = DataBinder.Eval(DataItem, "local").ToString();
                    if (local == "1")
                        rdoLocal.Items[0].Selected = true;
                    else
                        rdoLocal.Items[1].Selected = true;
                    ddlCountry.SelectedValue = DataBinder.Eval(DataItem, "training_cat_seq").ToString();
                    //ddlStatusRec.SelectedValue = DataBinder.Eval(DataItem, "record_status").ToString();
                    //txtRemarks.Text = DataBinder.Eval(DataItem, "remarks").ToString();
                    this.btnAddnew.Visible = false;
                    this.btnUpdate.Visible = true;
                }
                else
                {
                    this.btnUpdate.Visible = false;
                    this.btnAddnew.Visible = true;
                    //lblID.Text = Session["training_type_seq"].ToString();
                                    }
            }
         

        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
 
        protected void btnAddnew_Click(object sender, EventArgs e)
        {
            try
            {
                iniData.InsertTrainingTypes(txtName.Text,ddlCountry.SelectedValue, "1", rdoInternal.SelectedValue, rdoLocal.SelectedValue);
            }
            catch(Exception ex)
            {
                
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                iniData.UpdateTrainingTypes(lblID.Text, txtName.Text,ddlCountry.SelectedValue,"1",rdoInternal.SelectedValue,rdoLocal.SelectedValue);
            }
            catch (Exception ex)
            {

            }
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        private void bindCommandType()
        {
            DataTable InfoList = combo.ListTrainingType();

            ddlCountry.DataSource = InfoList;
            ddlCountry.DataBind();
        }
    }
}